package com.ruoyi.system.service.impl;

import com.ruoyi.common.core.text.Convert;
import com.ruoyi.system.domain.Xiaoxi;
import com.ruoyi.system.mapper.XiaoxiMapper;
import com.ruoyi.system.service.IXiaoxiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * 站内邮箱Service业务层处理
 * 
 * @author
 * @date
 */
@Service
public class XiaoxiServiceImpl implements IXiaoxiService 
{
    @Autowired
    private XiaoxiMapper xiaoxiMapper;

    /**
     * 查询站内邮箱
     * 
     * @param xiaoxiid 站内邮箱主键
     * @return 站内邮箱
     */
    @Override
    public Xiaoxi selectXiaoxiByXiaoxiid(String xiaoxiid)
    {
        return xiaoxiMapper.selectXiaoxiByXiaoxiid(xiaoxiid);
    }

    /**
     * 查询站内邮箱列表
     * 
     * @param xiaoxi 站内邮箱
     * @return 站内邮箱
     */
    @Override
    public List<Xiaoxi> selectXiaoxiList(Xiaoxi xiaoxi)
    {
        return xiaoxiMapper.selectXiaoxiList(xiaoxi);
    }

    /**
     * 新增站内邮箱
     * 
     * @param xiaoxi 站内邮箱
     * @return 结果
     */
    @Override
    public int insertXiaoxi(Xiaoxi xiaoxi)
    {
        return xiaoxiMapper.insertXiaoxi(xiaoxi);
    }

    /**
     * 修改站内邮箱
     * 
     * @param xiaoxi 站内邮箱
     * @return 结果
     */
    @Override
    public int updateXiaoxi(Xiaoxi xiaoxi)
    {
        return xiaoxiMapper.updateXiaoxi(xiaoxi);
    }

    /**
     * 批量删除站内邮箱
     * 
     * @param xiaoxiids 需要删除的站内邮箱主键
     * @return 结果
     */
    @Override
    @Transactional
    public int deleteXiaoxiByXiaoxiids(String xiaoxiids)
    {
        int ok=1;
        int result1 = xiaoxiMapper.deleteXiaoxiByXiaoxiids(Convert.toStrArray(xiaoxiids));
        if (result1==0){
            ok=0;
            throw new RuntimeException("删除邮件失败");
        }
        int result2 = xiaoxiMapper.deleteXiaoxiJieshourenByXiaoxiids(Convert.toStrArray(xiaoxiids));
        if (result2<0){
            ok=0;
            throw new RuntimeException("删除邮件接收人关联表失败");
        }
        return ok;
    }

    /**
     * 删除站内邮箱信息
     * 
     * @param xiaoxiid 站内邮箱主键
     * @return 结果
     */
    @Override
    public int deleteXiaoxiByXiaoxiid(String xiaoxiid)
    {
        return xiaoxiMapper.deleteXiaoxiByXiaoxiid(xiaoxiid);
    }

    /**
     * @param xiaoxiid
     * @param jieshourenid
     */
    @Override
    public void insertXiaoxiJieshouren(String xiaoxiid, String jieshourenid) {
        xiaoxiMapper.insertXiaoxiJieshouren(xiaoxiid,jieshourenid);
    }

    /**
     * @param xiaoxi
     * @return
     */
    @Override
    public List<Xiaoxi> selectInBoxList(Xiaoxi xiaoxi) {
        return xiaoxiMapper.selectInBoxList(xiaoxi);
    }

    @Override
    public List<Xiaoxi> selectInBoxWeiduList(Xiaoxi xiaoxi) {
        return xiaoxiMapper.selectInBoxWeiduList(xiaoxi);
    }

    /**
     * @param ids
     * @param userId
     * @return
     */
    @Override
    public int deleteXiaoxiJieshourenByXiaoxiids(String ids, Long userId) {
        return xiaoxiMapper.deleteXiaoxiJieshourenByXiaoxiidsUserid(Convert.toStrArray(ids),userId);
    }

    /**
     * @param ids
     * @return
     */
    @Override
    public int deleteXiaoxiByids(String ids) {
        return xiaoxiMapper.deleteXiaoxiByXiaoxiids(Convert.toStrArray(ids));
    }

    /**
     * @param id
     * @return
     */
    @Override
    public int Yuedu(String xiaoxiid,String shoujianrenid) {
        return xiaoxiMapper.Yuedu(xiaoxiid,shoujianrenid);
    }
}
